app.controller('DriverUploadCtrl', function ($scope, $modalInstance, $modal, toaster, param, ajax, fileUpload, cos) {

	$scope.submitting = false;
	$scope.param = param;
	if ($scope.param.data == null) {
		$scope.param.data = {};
	}

	if ($scope.param.type == "update") {
		$scope.flag = true;
	}

	$scope.uploadAff = function () {
		window.open($scope.param.data.attachment);
	};

	$scope.ok = function () {
		var uploadUrl = cos.host() + cos.img() + "?attributeName=driver";
		if ($scope.myForm.$valid) {
			if ($scope.fileToUpload != undefined) {
				fileUpload.upload($scope.fileToUpload, uploadUrl, null,
					function (result) {
						if (result.code == 200) {
							$scope.param.data.attachment = result.filePath;;
							$modalInstance.close($scope.param);

						} else {
							toaster.pop('error', '错误', result.message);
						}
					}, function () {
						toaster.pop('error', '错误', '文件上传失败！');
						$scope.uploading = false;
					}
				);
			} else {
				toaster.pop('warning', '提示', '请上传附件！');
				$scope.submitting = false;
				return;
			}
		}
	};

	$scope.cancel = function () {
		$modalInstance.dismiss('cancel');
		$scope.submitting = false;
	};
});